package com.qzimp.fujiancuo.service.impl;

import com.qzimp.fujiancuo.entity.Reservation;

import com.qzimp.fujiancuo.mapper.ReservationMapper;
import com.qzimp.fujiancuo.mapper.VisitorMapper;
import com.qzimp.fujiancuo.service.ReservationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

@Service
public class ReservationServiceImpl implements ReservationService {

    @Autowired
    private ReservationMapper reservationMapper;

    @Autowired
    private VisitorMapper visitorMapper;

    @Override
    public void addReservation(Reservation reservation) {
        // 检查访客是否存在
        if (!isVisitorExists(reservation.getVisitorId())) {
            throw new IllegalArgumentException("访客不存在，无法添加预约");
        }
        // 添加预约
        reservationMapper.addReservation(reservation);
    }

    @Override
    public void deleteReservation(Long reservationId) {
        reservationMapper.deleteReservation(reservationId);
    }

    @Override
    public void updateReservationStatus(Long reservationId, String status) {
        reservationMapper.updateReservationStatus(reservationId, status);
    }

    @Override
    public List<Reservation> getReservationsByVisitorId(Long visitorId) {
        return reservationMapper.getReservationsByVisitorId(visitorId);
    }

    @Override
    public boolean isVisitorExists(Long visitorId) {
        // 查询访客是否存在
        return visitorMapper.getVisitorById(visitorId) != null;
    }
}